package com.dragon.common.modules.file.common.enums;

import com.dragon.utils.StringUtil;

/**
 * @author Chris Chan
 * Create On 2023/4/13 5:47
 * Use for: 文件媒体类型枚举
 * Explain:
 * 主要用于存储分类
 */
public enum MediaTypeEnum {
//    private static final int file=0;
//    private static final int arh=0;
//    private static final int doc=0;
//    private static final int xls=0;
//    private static final int ppt=0;
//    private static final int pdf=0;
//    private static final int image=0;
//    private static final int audio=0;
//    private static final int video=0;
//    private static final int soft=0;

    FILE(0, "file", "file", "普通文件"),
    ARH(1, "arh", "arh", "压缩包"),
    DOC(2, "doc", "doc", "word文件"),
    XLS(3, "xls", "xls", "excel文件"),
    PPT(4, "ppt", "ppt", "powerpoint文件"),
    PDF(5, "pdf", "pdf", "电子书"),
    IMAGES(6, "images", "image", "图片文件"),
    AUDIO(7, "audio", "audio", "音频文件"),
    VIDEO(8, "video", "video", "视频文件"),
    SOFT(9, "soft", "soft", "软件");


    private int code;
    private String mediaType;
    private String savePath;
    private String desc;

    MediaTypeEnum(int code, String mediaType, String savePath, String desc) {
        this.code = code;
        this.mediaType = mediaType;
        this.savePath = savePath;
        this.desc = desc;
    }

    public static MediaTypeEnum byCode(int code) {
        MediaTypeEnum[] values = values();
        for (MediaTypeEnum value : values) {
            if (value.code == code) {
                return value;
            }
        }
        return FILE;
    }

    public static MediaTypeEnum byMediaType(String mediaType) {
        if (StringUtil.isEmpty(mediaType)) {
            return FILE;
        }
        MediaTypeEnum[] values = values();
        for (MediaTypeEnum value : values) {
            if (value.mediaType.equals(mediaType)) {
                return value;
            }
        }
        return FILE;
    }

    public static MediaTypeEnum matchMediaType(String mediaType) {
        if (StringUtil.isEmpty(mediaType)) {
            return FILE;
        }
        MediaTypeEnum[] values = values();
        for (MediaTypeEnum value : values) {
            if (mediaType.startsWith(value.mediaType)) {
                return value;
            }
        }
        return FILE;
    }

    public int getCode() {
        return code;
    }

    public String getMediaType() {
        return mediaType;
    }

    public String getSavePath() {
        return savePath;
    }

    public String getDesc() {
        return desc;
    }
}
